# -*- coding: utf-8 -*-
"""
@Time    : 2023/3/10 15:53
@Author  : JackXia
@Email   : 915624876@qq.com
@QQ      : 915624876
@File    : 977.有序数组的平方.py
@Software: PyCharm
"""


class Solution(object):
    def sortedSquares(self, nums) -> list:
        p1 = 0
        nums_length = len(nums)
        p2 = nums_length - 1
        ret_list = []
        while p1 <= p2:
            num_p1 = nums[p1] * nums[p1]
            num_p2 = nums[p2] * nums[p2]
            if num_p1 > num_p2:
                ret_list.insert(0, num_p1)
                p1 += 1
            elif num_p1 <= num_p2:
                ret_list.insert(0, num_p2)
                p2 -= 1
            # elif num_p1 == num_p2:
            #     ret_list.insert(0, num_p1)
            #     ret_list.insert(0, num_p2)
            #     p1 += 1
            #     p2 -= 1
        return ret_list


if __name__ == '__main__':
    nums = [-4, -3, -2, -1, 0, 0, 1, 1, 3, 10]
    print(Solution().sortedSquares(nums))
